package com.larry.spark.rdd.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object RDD_Oper_Intersection {

  def main(args: Array[String]): Unit = {
    //TODO  使用spark 交集 并集 差集

    val conf = new SparkConf().setMaster("local[*]").setAppName("rdd")
    val sc = new SparkContext(conf)

    val rdd: RDD[Int] = sc.makeRDD(List(1,2,3,4),2)
    val rdd1: RDD[Int] = sc.makeRDD(List(3,4,5,6),2)

    //交集
    println(rdd.intersection(rdd1).collect().mkString(","))

    //并集
    println(rdd.union(rdd1).collect().mkString(","))

    //差集
    println(rdd.subtract(rdd1).collect().mkString(","))

    //拉链
    println(rdd.zip(rdd1).collect().mkString(","))

    sc.stop()
  }
}
